import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_slidable/flutter_slidable.dart';
import 'package:moose_app/ui/values/values.dart';
import 'package:moose_app/ui/widgets/user/user_avatar.dart';

class ATHMessageItem extends StatelessWidget {
  final Function press;

  ATHMessageItem({this.press});

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      child: Slidable(
        actionPane: SlidableDrawerActionPane(),
        actionExtentRatio: 0.25,
        secondaryActions: <Widget>[
          IconSlideAction(
            caption: '删除',
            color: Colors.black45,
            icon: Icons.more_horiz,
            onTap: () => _showSnackBar(context, '删除'),
          ),
          IconSlideAction(
            caption: '取消关注',
            color: Colors.red,
            icon: Icons.delete,
            onTap: () => _showSnackBar(context, '取消关注'),
          ),
        ],
        child: Container(
          margin: EdgeInsets.symmetric(vertical: kSize10),
          child: Row(
            crossAxisAlignment: CrossAxisAlignment.center,
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: <Widget>[
              ATHUserAvatar(),
              Expanded(
                child: Container(
                  padding: EdgeInsets.only(left: kSize8),
                  decoration: BoxDecoration(
                      border: Border(bottom: BorderSide(color: kColorF1))),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: <Widget>[
                      Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: <Widget>[
                          Expanded(
                            child: Container(
                              child: Text(
                                "测试用户",
                                maxLines: 1,
                                overflow: TextOverflow.ellipsis,
                                style: TextStyle(
                                    color: kColor33, fontSize: kFontSize32),
                              ),
                            ),
                          ),
                          Container(
                            margin: EdgeInsets.only(left: kSize8),
                            child: Text(
                              "2 分钟",
                              maxLines: 1,
                              overflow: TextOverflow.ellipsis,
                              style: TextStyle(
                                  color: kColor33, fontSize: kFontSize24),
                            ),
                          ),
                        ],
                      ),
                      Row(
                        crossAxisAlignment: CrossAxisAlignment.center,
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: <Widget>[
                          Expanded(
                            child: Container(
                              margin: EdgeInsets.symmetric(vertical: kSize10),
                              child: Text(
                                "评论 评论 评论 评论评论 评论 评论 评论 评论 评论 评论评论 评论 评论 评论 评论 评论 评论评论 评论 评论",
                                maxLines: 1,
                                overflow: TextOverflow.ellipsis,
                                style: TextStyle(
                                    fontSize: kFontSize28, color: kColor99),
                              ),
                            ),
                          ),
                          Container(
                            padding: EdgeInsets.symmetric(
                                vertical: kSize4, horizontal: kSize8),
                            decoration: BoxDecoration(
                                color: Colors.redAccent,
                                borderRadius:
                                    BorderRadius.all(Radius.circular(kSize12))),
                            child: Text('66',
                                style: TextStyle(
                                    fontSize: kFontSize20, color: kColorF1),
                                textAlign: TextAlign.center),
                          )
                        ],
                      )
                    ],
                  ),
                ),
              ),
            ],
          ),
        ),
      ),
      onTap: press,
    );
  }

  void _showSnackBar(BuildContext context, String text) {
    ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(text)));
  }
}
